/**
 * Created by NamLaptop on 7/13/2014.
 */

var MyTileNoEvent = MySprite.extend({
    ctor: function(src){
        this._super();
        this.src = src;
        this.initWithFile(src);
        this.pos = {x: 0, y: 0};
        this.ID = null;
    }
});

var MyTile = MyTileNoEvent.extend({

    ctor: function(src){
        this._super(src);
        this.textSprite = null;
        this.isShowText = false;
        this.textWin = "";
    },

    showText: function(text){
        if(this._parent != null){
            if(this.textWin.length > 0){
                if(this.textWin.indexOf(text) < 0) {
                    this.textWin = text + ", " + this.textWin;
                }
            }
            else{
                this.textWin = text;
            }

            if(this.textSprite == null){
                this.textSprite = cc.LabelTTF.create(this.textWin, INFO.MESSAGEBOX.FONT, 14);
                this.textSprite.setColor(cc.BLUE);
            }
            else{
                this.textSprite.setString(this.textWin);
            }

            this.textSprite.setPosition(this.getPositionX() - 2, this.getPositionY() + this.getBoundingBox().getHeight() /2 - 14);
            if(!this.isShowText){
                this.isShowText = true;
                this._parent.addChild(this.textSprite, INFO.TILE.ORDER_PICKED + 20);
            }
        }
    },

    hideText: function(){
        if(this.isShowText){
            this.textWin = "";
            this._parent.isShowText = false;
            this._parent.removeChild(this.textSprite);
        }
    },

    defaultMouseOver: function(){
        var move = cc.MoveBy.create(0.1, cc.p(0,7));
        this.runAction(cc.Sequence.create(move));
        if(this.textSprite != null){
            var move2 = cc.MoveBy.create(0.1, cc.p(0,7));
            this.textSprite.runAction(cc.Sequence.create(move2));
        }
    },

    defaultMouseOut: function(){
        var move = cc.MoveBy.create(0.1, cc.p(0,-7));
        this.runAction(cc.Sequence.create(move));
        if(this.textSprite != null){
            var move2 = cc.MoveBy.create(0.1, cc.p(0,-7));
            this.textSprite.runAction(cc.Sequence.create(move2));
        }
    },

    // Override
    onMouseOver: function(){
        this.defaultMouseOver();
        //this.setColor(cc.RED);
    },

    onMouseOut: function(){
        this.defaultMouseOut();
        //this.setColor(cc.WHITE);
    },

    //Override
    _onTap: function(touch, event){
        this.onTap(touch, event);
    }
});

